using Circus.CodeEditor;

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
namespace Circus.Syntax.CodeCompletion
{
	public class CodeSnippets : CodeCompletionProvider,ICodeSnippetsProvider, ICodeCompletionProvider, IList<IComparable>, ICollection<IComparable>, IEnumerable<IComparable>, IEnumerable
	{
		private ICodeSnippetMember parent;
		public new CodeSnippet this[int index]
		{
			get
			{
				return base[index] as CodeSnippet;
			}
			set
			{
				base[index] = value;
			}
		}
		public override int ColumnCount
		{
			get
			{
				return 1;
			}
		}
		public override ImageList Images
		{
			get
			{
				return (base.Images != null) ? base.Images : ((this.GetParent() != null) ? this.GetParent().Images : null);
			}
			set
			{
				base.Images = value;
			}
		}
		public override string EditPath
		{
			get
			{
				return (this.parent != null) ? this.parent.EditPath : string.Empty;
			}
		}
	
		public CodeSnippets()
		{
			this.ShowDescriptions = true;
			this.UseIndent = false;
			this.EditField = StringConsts.CodeSnippetsEditField;
		}
		public CodeSnippets(ICodeSnippetMember parent) : this()
		{
			this.parent = parent;
		}
		public virtual CodeSnippet AddSnippet()
		{
			CodeSnippet codeSnippet = new CodeSnippet(this);
			base.Add(codeSnippet);
			return codeSnippet;
		}
		public virtual CodeSnippet InsertSnippet(int index)
		{
			CodeSnippet codeSnippet = new CodeSnippet(this);
			base.Insert(index, codeSnippet);
			return codeSnippet;
		}
		public virtual CodeSnippet FindByShortcut(string shortcut, bool caseSensitive)
		{
			CodeSnippet result;
			using (List<IComparable>.Enumerator enumerator = base.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					CodeSnippet codeSnippet = (CodeSnippet)enumerator.Current;
					if (string.Compare(shortcut, codeSnippet.Header.Shortcut, !caseSensitive) == 0)
					{
						result = codeSnippet;
						return result;
					}
				}
			}
			result = null;
			return result;
		}
		public virtual bool ShouldIndent(CodeSnippet snippet)
		{
			return this.UseIndent || snippet.Header.Title.StartsWith("#");
		}
		public override string GetDescription(int index)
		{
			return this[index].Description;
		}
		public override int GetImageIndex(int index)
		{
			return this[index].ImageIndex;
		}
		public override bool ColumnVisible(int column)
		{
			return true;
		}
		public override string GetColumnText(int index, int column)
		{
			return (column == 0) ? this.GetName(index) : string.Empty;
		}
		public override string GetText(int index)
		{
			return this[index].Code.Code;
		}
		public override string GetName(int index)
		{
			return this[index].Header.Title;
		}
		public override ICodeCompletionProvider GetParent()
		{
			return (this.parent != null) ? this.parent.Parent : null;
		}
	}
}
